import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index'
import LayoutNoneSiderBar from '@/layout/other'
import dataWatch from './modules/data_watch'
Vue.use(VueRouter)

/**
 * 路由相关属性说明
 * hidden: 当设置hidden为true时，意思不在sideBars侧边栏中显示
 * mete{
 * title: xxx,  设置sideBars侧边栏名称
 * icon: xxx,  设置ideBars侧边栏图标
 * noCache: true  当设置为true时不缓存该路由页面
 * }
 */
export const currencyRoutes = [
	{
		path: '/',
		name: 'home',
		component: LayoutNoneSiderBar,
		redirect: 'statics/dashboard'
		/* children: [
			{
				path: 'organizations',
				name: 'organizations',
				component: () => import('@/views/mech-choise/index'),
				meta: {
					title: '机构选择',
					icon: 'icon-caidanlan_jigouxuanze'
				}
			}
		] */
	},
	{
		path: '/home',
		name: 'home',
		component: LayoutNoneSiderBar,
		redirect: '/organizations',
		children: [
			{
				path: 'organizations',
				name: 'organizations',
				component: () => import('@/views/mech-choise/index'),
				meta: {
					title: '机构选择',
					icon: 'icon-caidanlan_jigouxuanze'
				}
			}
		]
	},
	{
		path: '/task-manager',
		name: 'taskManager',
		component: Layout,
		redirect: '/task-manager',
		children: [
			{
				path: 'index',
				name: 'taskmanager',
				component: () => import('@/views/task-mg'),
				meta: {
					title: '任务管理',
					icon: 'icon-caidanlan_renwuguanli'
				}
			}
		]
	},
	{
		path: '/archive-record',
		name: 'ArchiveRecord',
		component: Layout,
		redirect: '/archive-record',
		children: [
			{
				path: 'index',
				name: 'Archive',
				component: () => import('@/views/archive-record'),
				meta: {
					title: '检查记录',
					icon: 'icon-caidanlan_guidangjilu'
				}
			},
			{
				path: 'details',
				name: 'ArchiveDetail',
				hidden: true,
				component: () => import('@/views/archive-record/detail'),
				meta: { title: '', icon: 'icon-caidanlan_guidangjilu' }
			}
		]
	},
	{
		path: '/archive-record-doctor',
		name: 'ArchiveRecordDoctor',
		component: Layout,
		redirect: 'archive-record-doctor',
		children: [
			{
				path: 'index',
				name: 'ArchiveDoctor',
				component: () => import('@/views/archive-record-doctor'),
				meta: {
					title: '检查记录',
					icon: 'icon-caidanlan_guidangjilu'
				}
			},
			{
				path: 'details',
				name: 'ArchiveDetailsDoctor',
				hidden: true,
				component: () => import('@/views/archive-record-doctor/detail'),
				meta: {
					title: ''
					// icon: 'icon-caidanlan_guidangjilu'
				}
			}
		]
	},
	{
		path: '/log',
		component: Layout,
		redirect: '/doctor',
		meta: {
			title: '日志管理',
			icon: 'icon-caidanlan_rizhiguanli'
		},
		children: [
			{
				path: 'doctor',
				name: 'DoctorVist',
				component: () => import('@/views/log-mg/doctor'),
				meta: {
					title: '医生调阅'
				}
			},
			{
				path: 'patient',
				name: 'PatientVisit',
				component: () => import('@/views/log-mg/patient'),
				meta: {
					title: '患者访问'
				}
			},
			{
				path: 'message',
				name: 'MessageCheck',
				component: () => import('@/views/log-mg/message'),
				meta: {
					title: '短信审计'
				}
			}
		]
	},
	{
		path: '/report-quality',
		component: Layout,
		redirect: '/report-quality',
		children: [
			{
				path: 'index',
				name: 'reoportQuality',
				component: () => import('@/views/report-quality'),
				meta: {
					title: '质量报告',
					icon: 'el-icon-s-data'
				}
			}
		]
	},
	{
		path: '/visit',
		component: Layout,
		redirect: '/visit/auth',
		meta: {
			title: '访问管理',
			icon: 'icon-caidanlan_fangwenshouquan'
		},
		children: [
			{
				path: 'auth',
				name: 'accessAuth',
				component: () => import('@/views/visit-mg'),
				meta: {
					title: '访问授权',
					icon: 'icon-caidanlan_fangwenshouquan'
				}
			},
			{
				path: 'approval',
				name: 'shareApproval',
				component: () => import('@/views/visit-mg'),
				meta: {
					title: '分享审批',
					icon: 'icon-caidanlan_fangwenshouquan'
				}
			},
			{
				path: 'record',
				name: 'shareRecord',
				component: () => import('@/views/share-record'),
				meta: {
					title: '分享记录',
					icon: 'icon-fenxiangjilu'
				}
			}
		]
	},
	{
		path: '/parameter',
		component: Layout,
		redirect: '/parameter',
		children: [
			{
				path: 'collection',
				name: 'collectionConfig',
				component: () => import('@/views/collect-mg'),
				meta: {
					title: '采集参数',
					icon: 'icon-caidanlan_caijipeizhi'
				}
			},
			{
				path: '/create-client',
				name: 'crateClient',
				component: () => import('@/views/collect-mg/createClient.vue'),
				hidden: true
			},
			{
				path: 'other',
				name: 'parameterConfig',
				component: () => import('@/views/parameter-mg'),
				meta: {
					title: '其他参数',
					icon: 'icon-caidanlan_canshushezhi'
				}
			}
		]
	},
	{
		path: '/other-read',
		component: LayoutNoneSiderBar,
		redirect: '/other-read',
		children: [
			{
				path: 'index',
				name: 'parameterConfig',
				component: () => import('@/views/H5/img'),
				meta: {
					title: '调阅界面',
					icon: 'icon-caidanlan_canshushezhi'
				}
			}
		]
	},
	{
		path: '/redirect', // 重定向路由
		component: Layout,
		hidden: true,
		name: 'redirect',
		children: [
			{
				path: '/redirect/:path*',
				component: () => import('@/layout/components/sideBar/redirect')
			}
		]
	},

	...dataWatch // 数据监管
]

const creatRouter = () =>
	new VueRouter({
		routes: currencyRoutes,
		scrollBehavior () {
			return {
				x: 0,
				y: 0
			}
		}
	})

const router = creatRouter()

// 导航守卫
router.beforeEach(async (to, from, next) => {
	if (to.meta.title) {
		//判断是否有标题
		document.title = '医网云—存储共享'
	}
	/* 	var reg = /\/([^\/]*)\//g
	var systemType = reg.exec(to.path)[1]
	if (sessionStorage.getItem('systemArray') !== 'undefined') {
		var arr = JSON.parse(sessionStorage.getItem('systemArray'))
		for (var i in arr) {
			if (arr[i].product_code === systemType) {
				sessionStorage.setItem('lastname', arr[i].id)
			}
		}
	} */
	if (to.path === '/login') {
		next()
	}
	else {
		// if (from.path === '/login') {
		next()
	}
})
router.afterEach((to, from, next) => {
	// 跳到每个页面的时候 让页面滑动到最顶端
	document.body.scrollTop = 0
	document.documentElement.scrollTop = 0
})

export default router
